/**
 * 0031
 *  
 * @Author : Ruoyu Wang
 * @DateTime : 24-10-27 下午3:55
 */

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    void nextPermutation(vector<int> &nums) {
        int idx = nums.size() - 2;
        while (idx >= 0 && nums[idx] >= nums[idx + 1]) {
            idx--;
        }
        if (idx == -1) {
            reverse(nums.begin(), nums.end());
            return;
        }
        int k = nums.size() - 1;
        while (nums[k] <= nums[idx]) {
            k--;
        }
        swap(nums[k], nums[idx]);
        for (int i = idx + 1, j = nums.size() - 1; i < j; ++i, --j) {
            swap(nums[i], nums[j]);
        }
        return;
    }
};

int main() {

    return 0;
}